package ink.zhaohui.bytebuddy;

import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;

import java.lang.instrument.Instrumentation;
import net.bytebuddy.agent.builder.AgentBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AgentTool {

  final static Logger logger = LoggerFactory.getLogger(AgentTool.class);

  private static final String CONTROLLER_NAME = "ink.zhaohui";

  public static void premain(String agentArgs, Instrumentation inst) {
    logger.info("premain args:{}", agentArgs);
    AgentBuilder builder = new AgentBuilder.Default()
        .type(nameStartsWith(CONTROLLER_NAME))
        .transform(new AgentTransformer());
    builder.installOn(inst);
  }
}
